package com.hmall.search.controller;

import com.hmall.common.PageDTO;
import com.hmall.common.client.ItemClient;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import com.hmall.search.service.Impl.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Saint.Martine
 * @since 2022/12/9 12:53
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService iSearchService;

    //自动补全
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return iSearchService.getSuggestions(prefix);
    }

    //过滤项聚合功能
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams requestParams) {
        return iSearchService.filters(requestParams);
    }

    //搜索功能
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params) {
        return iSearchService.search(params);
    }
}
